package com.hzystudynote;

import java.util.ArrayList;
import java.util.Comparator;

/** @author ASUS */
public class ObjsortbylambdaCmp {
  public static void main(String[] args) {
    ObjsortbylambdaCmp obj = new ObjsortbylambdaCmp();
    obj.demoForComparator();
  }

  public void demoForComparator() {
    SweetHeart love1 = new SweetHeart("猪可爱", "pig");
    SweetHeart love2 = new SweetHeart("哈士奇", "dog");
    SweetHeart love3 = new SweetHeart("大火鸡", "chicken");
    ArrayList<SweetHeart> loveList = new ArrayList<>();
    loveList.add(love1);
    loveList.add(love2);
    loveList.add(love3);
    loveList.sort(
        new Comparator<>() {
          @Override
          public int compare(SweetHeart sweet1, SweetHeart sweet2) {
            return sweet2.type.compareTo(sweet1.type);
          }
        });
    loveList.sort((sweet1, sweet2) -> sweet2.type.compareTo(sweet1.type));
    System.out.println("按类型首字母排序(降序)后结果如下");
    for (SweetHeart love : loveList) {
      System.out.println(love.toString());
    }
  }
}

class SweetHeart {
  String name;
  String type;

  public SweetHeart(String name, String type) {
    this.name = name;
    this.type = type;
  }

  @Override
  public String toString() {
    return "name is " + this.name + "; type is " + this.type;
  }
}
